package com.mk.expression;

import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

public class SPELTemplate {

    public static void main(String[] args) {
        
        Rule r = new Rule();
        r.setPrice("0.9");
        
        ExpressionParser parser = new SpelExpressionParser();
        StandardEvaluationContext simpleContext = new StandardEvaluationContext();

        simpleContext.setVariable("r", r);

        String randomPhrase = parser.parseExpression(
                "hprice * #{#r.getPrice()}",
                new TemplateParserContext()).getValue(simpleContext,String.class);

//        String randomPhrase = parser.parseExpression(
//                "hprice * #{Price}",
//                new TemplateParserContext()).getValue(simpleContext,String.class);
        
        System.out.println(randomPhrase);
        
        
    }

}
